const path = require('path')
const webpack = require('webpack')
const os = require('os')
const mockServerPath = path.resolve(__dirname, './mock/mockServer.js')
const mockServer = require(mockServerPath)
const throwError = (message) =>
  throwUnexpectedConfigError({
    packageName: 'craco',
    githubRepo: 'gsoft-inc/craco',
    message,
    githubIssueQuery: 'webpack',
  });
module.exports = {
  style: {
    postcss: {
      loaderOptions: () => {
        const obj = {
          postcssOptions: {
            ident: 'postcss',
          }
        }
        return obj;
      }
    }
  },
  devServer: {
    port: 3001,
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    onBeforeSetupMiddleware: (server) => {
      server.app.use('*', mockServer())
    }
  },
  webpack: {
    alias: {
      '@': path.resolve(__dirname, 'src/').toString()
    },
    plugins: [
      new webpack.DefinePlugin({
        'process.env.SERVER_URL': JSON.stringify(`${os.networkInterfaces()['en0'].filter((obj) => obj['family'] == 'IPv4')[0]['address']}:3001`)
      })
    ],

  },
  typescript: {
    enableTypeChecking: true
  }
}